<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="<?php echo $baseurl?>">Trang chủ</a> <span class="divider">/</span></li>
        <li class="active">Phân quyền</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Phân quyền</h1> <span></span>
</div>
<div class="maincontent">
    <?php if(validation_errors()):?>
        <div class="alert alert-error" style="margin: 10px 10px 10px 40px;">
          <button data-dismiss="alert" class="close" type="button">×</button>
          <?php echo validation_errors(); ?>
        </div>
    <?php endif;?>
    
    <div class="contentinner content-dashboard">    
    
    <?php $attr = array('class' => 'stdform'); echo form_open('', $attr)?>
    <input type="hidden" name="checkSelect" id="selectUser" />
    <p style="margin: 35px 5px 10px 0px;font-size: 18px;">
        Nhóm quyền và quản trị
            <hr style="border-top: 1px soild #DCDCDC !important;margin: 0px;" />
    </p>
    <p>
    	<label>Nhóm quyền ( * )</label>
        <span class="field">
            <select id="permission" name="permission">
                <?php echo $permission;?>
            </select>
        </span>
    </p>
    <p>
    	<label>Quản trị ( * )</label>
        <span class="field">
            <select id="userdata" name="user">
            <option value="selectNull">Vui lòng chọn quản trị</option>
                <?php echo $selectUser;?>
            </select>
        </span>
    </p>
    <p id="list-module" style="margin: 35px 5px 10px 0px;font-size: 18px;display: none;float: left;width: 100%;">
            <label class="hr">Danh sách chức năng</label>
            <span class="field" style="float: left;width: 78%;margin: 20px 0px 20px 220px;border-top: 1px soild #DCDCDC !important;">
                <input type="hidden" name="sizeModule" id="sizeModule" value="<?php echo sizeOf($module);?>" />
    			<?php if(!in_array($module, array(null, ''. '0'))):?>
                <?php foreach($module AS $le=>$el):?>
                <span class="btnper fixbtnper " style="float: left;margin: 10px 0px;margin-right: 25px;">
                    <label style="width: auto; float: left; margin: -6px -10px 0px 0px;" class="btn_click" for="id_<?php echo $el->orderby;?>"><?php echo $el->name_module?></label>
                    <input type="radio" name="module[]" class="btn_click" id="id_<?php echo $el->orderby;?>" value="<?php echo $el->id;?>" />
                </span>
                <?php endforeach;endif;?>   
            </span>    
    </p>
    
    <p id="permission_box" style="margin: 35px 5px 20px 0px;font-size: 18px;display: none">
        <label class="hr">Quyền</label>
        <span class="field" id="permission_show" style="margin-top: 20px;margin-bottom: 20px;float: left">
            
        </span>
    </p>
    
    <p style="width: 100%;float: left">
        <label>&nbsp;</label>
        <button class="btn btn-rounded" type="submit" name="savePermission"> <i class="iconfa-ok"></i> &nbsp; Lưu lại</button>
        <button class="btn btn-rounded" type="button" onclick="window.location='<?php echo $baseurl.'manage/system/permission-list'?>'"> <i class="icon-arrow-right"></i> &nbsp; Hủy bỏ</button>
    </p>
    
    </form>
    </div>
</div>
<style>
.hr{
    margin: 10px 0px;padding-bottom: 10px !important;width: 98% !important;float: left;text-align: left !important;font-size: 19px;border-bottom: 1px solid #fff;border-bottom: 1px solid #ececef;box-shadow: 0px 1px 0px #FFF;
}
span.btnper.fixbtnper {
    padding: 0px 10px;
    min-width: 200px;
}
</style>
<script>
$(document).ready(function()
{
    
    $("#userdata").change(function()
    {
        $("#selectUser").val('1');
        $("#list-module").show();
        $("#permission_box").show();
        
        var userID = $("#userdata").val();
        var val = $(this).val();
        var permissiondata = $("#permission").val();
        $.ajax({
            cache: false,
            type: "GET",
            url: '<?php echo $baseurl?>'+'manage-getpermission',
            data: ({user: userID, id_pg: permissiondata, module: val, __gift: csrf}),
            success: function(html)
            {
                $("#permission_box").show();
                $("#permission_show").html(html);
            }
        });
        
    });
    
    $("#permission").change(function()
    {
        $("#selectUser").val('1');
        var userID = $("#userdata").val();
        var val = $(this).val();
        var permissiondata = $("#permission").val();
        $.ajax({
            type: "GET",
            url: '<?php echo $baseurl?>'+'manage-getpermission',
            data: ({user: userID, id_pg: permissiondata, module: val, __gift: csrf}),
            success: function(html)
            {
                $("#permission_box").show();
                $("#permission_show").html(html);
            }
        });
        
    });
    
    var userID = $("#userdata").val();
    console.log('userIDuserIDuserIDuserID', userID);
    if(userID != 'selectNull')
    {
        $("#selectUser").val('1');
        $("#list-module").show();
        $("#permission_box").show();
    }
    
    
    var csrf = __gift;
    $(".btn_click").change(function(){
        
        $("#permission_show").html('Đang tải ...');
        var userID = $("#userdata").val();
        if(userID == 'selectNull')
        {
            console.log('userID', userID);
            jAlert('Vui lòng chọn một quản trị trước khi chọn module', 'Thông báo', function()
            {
                return false;
            });
            return false;
        }
         var val = $(this).val();
         var permissiondata = $("#permission").val();
         
         $.ajax({
            cache: false,
            type: "GET",
            url: '<?php echo $baseurl?>'+'manage-getpermission',
            data: ({user: userID, id_pg: permissiondata, module: val, __gift: csrf}),
            success: function(html)
            {
                $("#permission_box").show();
                $("#permission_show").html(html);
            }
        });
    });
});
</script>     